import { _decorator, Component, director, Label, Node, Vec3, tween } from 'cc';
const { ccclass, property } = _decorator;
import GlobalEvent from '../Global/GlobalEvent';
import LevelManager from '../managers/LevelManager';

@ccclass('gameScene')
export class gameScene extends Component {

    @property(Node)
    private fuhuo: Node = null;

    private bool = false;

    @property(Node)
    public gameBg: Node;
    @property(Node)
    private lvView: Node = null;

    private bgMoveLeft;


    protected onLoad(): void {
        globalThis.sceneData = this;


    }
    start() {
        GlobalEvent.emit('createM');

    }

    protected update(dt: number): void {

    }

    //关卡提升的变化
    guanQia() {
        if (this.bool) return;
        this.bool = true;
        // 下一关
        const levelManager = LevelManager.getInstance();
        levelManager.increaseLevel();


        // 玩家跑步动画
        // console.log('玩家跑步动作');

        // 场景向左移
        let gamebg = () => {

            this.bgMoveLeft = tween(this.gameBg)
                .by(1.0, { position: new Vec3(-700, 0, 0) })
                .call(() => {

                    // console.log('场景向左移了！');
                    // 生成新的怪物
                    GlobalEvent.emit('createM');
                    // globalThis.createM.createMonsters();
                    let lvView = this.lvView.getComponent(Label)
                    let level = LevelManager.getInstance()
                    let getlevel = level.getLevel()
                    lvView.string = `关卡:${getlevel}`

                    this.bool = false;
                })
                .start();
        }
        gamebg();

    }



    //继续按钮
    public resume() {
        this.fuhuo.active = false;
        director.resume()
    }


}

